﻿using System;
using System.Data;
using System.Collections.Generic;
using OgilvyOne.Model;
using OgilvyOne.DALFactory;
using OgilvyOne.IDAL;
using OgilvyOne.DALFactory.cofco.product;
namespace OgilvyOne.BLL
{
    /// <summary>
    /// BrandInfoBll
    /// </summary>
    public partial class BrandInfoBll
    {
        private readonly IBrandInfo dal = BrandInfoFactory.create();
        public BrandInfoBll()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string name,int BRAND_ID)
        {
            return dal.Exists(name,BRAND_ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BrandInfoModel model,string typeIdList)
        {
            return dal.Add(model, typeIdList);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BrandInfoModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int BRAND_ID)
        {

            return dal.Delete(BRAND_ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string BRAND_IDlist)
        {
            return dal.DeleteList(BRAND_IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BrandInfoModel GetModel(int BRAND_ID)
        {

            return dal.GetModel(BRAND_ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BrandInfoModel GetModelByOrderNum(int orderNum,string idlist)
        {

            return dal.GetModelByOrderNum(orderNum,idlist);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BrandInfoModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BrandInfoModel> DataTableToList(DataTable dt)
        {
            List<BrandInfoModel> modelList = new List<BrandInfoModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BrandInfoModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BrandInfoModel();
                    if (dt.Rows[n]["BRAND_ID"].ToString() != "")
                    {
                        model.Brandid = int.Parse(dt.Rows[n]["BRAND_ID"].ToString());
                    }
                    model.Brandname = dt.Rows[n]["BRAND_NAME"].ToString();
                    model.Brandimg = dt.Rows[n]["BRAND_IMG"].ToString();
                    model.Branddesc = dt.Rows[n]["BRAND_DESC"].ToString();
                    if (dt.Rows[n]["BRAND_TYPE_ID"].ToString() != "")
                    {
                        model.Brandtypeid = int.Parse(dt.Rows[n]["BRAND_TYPE_ID"].ToString());
                    }
                    if (dt.Rows[n]["ORDER_NUM"].ToString() != "")
                    {
                        model.Ordernum = int.Parse(dt.Rows[n]["ORDER_NUM"].ToString());
                    }
                    if (dt.Rows[n]["STATE"].ToString() != "")
                    {
                        model.State = int.Parse(dt.Rows[n]["STATE"].ToString());
                    }
                    if (dt.Rows[n]["ADD_TIME"].ToString() != "")
                    {
                        model.Addtime = DateTime.Parse(dt.Rows[n]["ADD_TIME"].ToString());
                    }
                    model.Addusername = dt.Rows[n]["ADDUSERNAME"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}
        public int getNum(string brandTypeId)
        {
            return dal.getNum(brandTypeId);
        }
        #endregion  Method
    }
}

